Repository navigation
fix(studio-server): a sealed preview's wait for a video's proxy copy passes its preflight - #7856
Conversation
…passes its preflight
jrusso1020
left a comment
There was a problem hiding this comment.
Verdict: approve. Reviewed at 03032f60.
The token route answers the proxy wait's CORS preflight and exposes the wait's response headers on the loads it grants. That lets a sealed preview fetch a video's proxy copy with Range and X-HF-Proxy-Priority.
What I checked
- Order of checks. The preflight is answered only after
tokens.matches(projectId, token)and the token segment is stripped. It also has to be anOPTIONSfromOrigin: null, ask forGET, and name a video path carryinghf-proxy. Anything else falls through to the server as before. The 204 carries no body and touches no file, so it reveals nothing beyond what the matched token already grants. TheGETstill goes through the preview route and its private-file checks. - Reuse.
isProxyWaitand the two header lists come out ofcaptureLoads.tsand are shared, so the capture page and the token route answer an opaque frame identically. That avoids a second copy. - Your "fails without the fix" claim:
- With
captureLoads.tsandopaqueFrameLoads.tsfrom main,preview.opaqueFrameLoads.test.tsfails 2 of 61: "answers its preflight with the proxy GET's method and headers" and "lets the frame read the proxy wait's headers on a granted load". - At head, that file plus
captureLoads.test.tspass 105/105 (core, parsers and lint built first, as CI does). - The five "left unanswered" cases cover the negative side: wrong file type, no proxy query, a non-opaque caller, a non-GET method, a wrong token.
- With
- The CI step runs the browser check inside the existing preview-video job with
if: success() || failure(). No permissions change. - No other reviews. CI is still running at this head (41 pass, 30 pending, 0 failed when I posted).
Nit (not blocking). Access-Control-Allow-Headers is a fixed list, not an echo of the request's, which is the safer shape. A runtime that later adds a header to the wait would fail its preflight, though, so a comment in proxyWait.ts pointing at PROXY_WAIT_ALLOWED_HEADERS would keep the two in step.
Need: yes · Size: ok · Reuse: isProxyWait and the header lists shared from captureLoads.ts · Simpler: already minimal · Structure: fine (checked captureLoadGrant's existing preflight; one shared owner, no split)
Risk: low — the extra preflight answer is reachable only after the token matches.
— Rames
What
A sealed preview (opaque origin, under its frame-token path) can now ask for a video's proxy copy. The runtime's wait (
core/runtime/proxyWait.ts) sendsRangeandX-HF-Proxy-Priority, so Chrome preflights it. The token route now answers that preflight, and lets the frame read the wait's own headers.preview/~<token>/, after the token check: anOPTIONSfromOrigin: null, asking forGET, on a video path with?hf-proxy=gets204withAccess-Control-Allow-Origin: null,Access-Control-Allow-Methods: GETandAccess-Control-Allow-Headers: Range, X-HF-Proxy-Priority. Any otherOPTIONSgoes on to the server as before.Access-Control-Expose-Headers: Retry-After, X-HF-Proxy-Progress, Content-Range.Why
Without this, a sealed preview cannot install a video's playable copy: the wait's preflight is refused, so the runtime reports the proxy as failed. Studio's preview is about to run sealed by default (#7846), so this lands first.
How
The header lists and the proxy-wait test already existed for sealed thumbnail captures in
captureLoads.ts. They are now exported from there (isProxyWait,PROXY_WAIT_ALLOWED_HEADERS,PREVIEW_EXPOSED_HEADERS) and the token route uses the same ones, so both answer an opaque frame alike. The token and the private-file checks are unchanged: the preflight is answered only after the token matches, and theGETstill goes through the preview route.No visible change
Reachable only from a sealed preview, which Studio does not use by default yet.
Test plan
fails without the fix:
cd packages/studio-server && vitest run src/routes/preview.opaqueFrameLoads.test.ts -t "proxy copy"(2 of its 7 tests fail onmain), and the new browser checknode packages/studio/tests/e2e/sealed-preview-proxy.mjs(onmain:TypeError: Failed to fetch, the preflight refused).On Linux, Node 24:
packages/studio-servervitest run: 110 files, 1989 tests, 3 runs in a row.VITE_STUDIO_OPAQUE_PREVIEW_ENABLED=1, Chrome 155, a project holdingclip.mov. From inside the sealed preview (originnull) the runtime's request shape (Range: bytes=0-0,X-HF-Proxy-Priority: 1) fails to fetch onmainand gets its answer with this change. It runs in CI next to the preview-video checks, on that job's Chrome.tsc --noEmit,oxfmt --check,oxlint, the comment ratchet andfallow auditare clean.